package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.UserUnionDTO;
import cn.com.blueInfo.bpm.person.response.UserUnionVO;
import cn.com.blueInfo.bpm.person.service.UserUnionService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 员工联合信息表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "员工联合信息 接口")
@RestController
@RequestMapping("/person/userUnion")
public class UserUnionController extends BaseController {

    @Autowired
    private UserUnionService userUnionService;

    /**
     * 新建员工联合信息
     * @param userUnionDTO 员工联合信息参数
     * @return ResultInfo
     */
    @Operation(summary = "新增员工联合信息")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createUserUnion(
            @Validated({Create.class, Default.class}) @RequestBody UserUnionDTO userUnionDTO) {
        return userUnionService.addUserUnion(userUnionDTO);
    }

    /**
     * 批量新建员工联合信息
     * @param userUnionDTOList 员工联合信息参数列表
     * @return ResultInfo
     */
    @Operation(summary = "新增员工联合信息")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateUserUnion(
            @Validated({Create.class, Default.class}) @RequestBody List<UserUnionDTO> userUnionDTOList) {
        return userUnionService.batchAddUserUnion(userUnionDTOList);
    }

    /**
     * 根据ID删除员工联合信息
     * @param userUnionId 员工联合信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除员工联合信息")
    @DeleteMapping("/removeInfo/{userUnionId}")
    public ResultInfo<Integer> deleteUserUnionById(
            @Parameter(name = "ID") @PathVariable Long userUnionId) {
        return userUnionService.removeUserUnion(userUnionId);
    }

    /**
     * 批量根据ID删除员工联合信息
     * @param userUnionIdList 员工联合信息ID列表
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除员工联合信息")
    @DeleteMapping("/removeInfoList/{userUnionIdList}")
    public ResultInfo<Integer> deleteUserUnionById(
            @Parameter(name = "ID") @PathVariable List<Long> userUnionIdList) {
        return userUnionService.batchRemoveUserUnion(userUnionIdList);
    }

    /**
     * 根据ID全量更新员工联合信息
     * @param userUnionId 员工联合信息ID
     * @param userUnionDTO 员工联合信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新员工联合信息")
    @PutMapping("/modifyInfo/{userUnionId}")
    public ResultInfo<Integer> updateUserUnionFull(
            @Parameter(name = "ID") @PathVariable Long userUnionId,
            @Validated({Update.class, Default.class}) @RequestBody UserUnionDTO userUnionDTO) {
        validateUpdateId(userUnionId, userUnionDTO.getId());
        return userUnionService.modifyUserUnion(userUnionDTO);
    }

    /**
     * 根据ID部分更新员工联合信息
     * @param userUnionId 员工联合信息ID
     * @param userUnionUpdatePartialDTO 员工联合信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新员工联合信息")
    @PatchMapping("/modifyPartialInfo/{userUnionId}")
    public ResultInfo<Integer> updateUserUnionPartial(
            @Parameter(name = "ID") @PathVariable Long userUnionId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            UserUnionDTO.UpdatePartialDTO userUnionUpdatePartialDTO) {
        validateUpdateId(userUnionId, userUnionUpdatePartialDTO.getId());
        return userUnionService.modifyUserUnionPartial(userUnionUpdatePartialDTO);
    }

    /**
     * 根据ID查询员工联合信息
     * @param userUnionId 员工联合信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询员工联合信息")
    @GetMapping("/getInfo/{userUnionId}")
    public ResultInfo<UserUnionVO> getUserUnionById(
            @Parameter(name = "ID") @PathVariable Long userUnionId) {
        return userUnionService.queryUserUnionById(userUnionId);
    }

    /**
     * 分页查询员工联合信息
     * @param userUnionQueryDTO 员工联合信息参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询员工联合信息")
    @GetMapping("/getInfos")
    public ResultInfo<Page<UserUnionVO>> getUserUnionPage(
            @Validated UserUnionDTO.QueryDTO userUnionQueryDTO) {
        return userUnionService.queryUserUnionPage(userUnionQueryDTO);
    }

    /**
     * 根据条件查询员工联合信息
     * @param userUnionQueryDTO 员工联合信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询员工联合信息")
    @GetMapping("/getInfoList")
    public ResultInfo<List<UserUnionVO>> getUserUnionList(
            @Validated UserUnionDTO.QueryDTO userUnionQueryDTO) {
        return userUnionService.queryUserUnionList(userUnionQueryDTO);
    }

}
